#! /bin/bash
#根据参数初始化配置文件
#param: -IP -NodeID
NCC_HOME=~/ncc
PRODUCT_HOME=~/ncc/product

if [ ! $# == 2 ]; then
	echo "Usage: $0 IP NodeID"
	exit
fi

if [ ! -d "$PRODUCT_HOME" ]; then  
	echo "$PRODUCT_HOME not exit!"
	exit  
fi  

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
#cd $DIR

# 替换当前目录下clusternodes.properties.tpl 中的ip和nid属性：
#localhost=p:ip -> -IP参数提供
perl -p -i -e "s/:ip/"$1"/g" $DIR/*.tpl
#nodeId=:nid -> -NodeID参数提供
perl -p -i -e "s/:nid/"$2"/g" $DIR/*.tpl
cp  $DIR/clusternodes.properties.tpl $PRODUCT_HOME/clusternodes.properties
cp  $DIR/raft.xml.tpl $PRODUCT_HOME/raft.xml
echo 'success'